
export function ReadOne(key,id){
  if(!id){
    return {}
  }
  let arr = Read(key);
  for(let i=0;i<arr.length;i++){
      let item = arr[i]
      if(item.id==id){
          return item;
      }
  }
  return {}
}
export function Read(key){
    let ds = localStorage.getItem(key)
    if(ds){
      return JSON.parse(ds)
    }
    return []
}
export function Save(key,item){
    let data = Read(key)
    let match = false
    let arr = []
    data.forEach((v)=>{
      if( v.id == item.id){
        arr.push(item)
        match = true
      }else{
        arr.push(v)
      }
    })
    if(!match){
      arr.push(item)
    }
    localStorage.setItem(key,JSON.stringify(arr))
}
export function Delete(key:string, id:string){
    let data = Read(key)
    let arr = []
    data.forEach((v)=>{
      if( v.id != id){
        arr.push(v)
      }
    })
    localStorage.setItem(key,JSON.stringify(arr))
}
